package com.cbtx.module_sp.ui.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.cbtx.module.common.bean.GoodsEntity
import com.cbtx.module.common.vm.TreasureDetailVM
import com.cbtx.module_sp.MyApplication
import com.cbtx.module_sp.R
import com.cbtx.module_sp.ui.activity.base.MyBaseVMActivity
import com.cbtx.module_sp.ui.adapter.ImageDetailAdapter
import com.txcb.lib.base.utils.LoadingDialogUtil
import kotlinx.android.synthetic.main.sp_activity_goods_detail.*

class GoodsDetailActivity: MyBaseVMActivity<TreasureDetailVM>() {


    companion object{
        fun start(activity:Activity,goodsBean: GoodsEntity.DataBean.ListBean){
            val intent = Intent(activity,GoodsDetailActivity::class.java)
            intent.putExtra("goodsBean", goodsBean)
            activity.startActivity(intent)
        }
    }

    var mAdapter:ImageDetailAdapter? = null

    override fun getPresenterClazz(): Class<TreasureDetailVM> {
         return TreasureDetailVM::class.java
    }

    override fun getLayoutId(): Int {

        return R.layout.sp_activity_goods_detail
    }

    override fun initView(savedInstanceState: Bundle?) {

        mVM.getIntent(intent)

        LoadingDialogUtil.showDialog(mActivity,"")
        mTvCode.text = "云屏编码: ${MyApplication.mAndroidId}"

        mAdapter = ImageDetailAdapter(mVM.mImageList)
        mRvDetailImages.layoutManager = LinearLayoutManager(mActivity)
        mRvDetailImages.adapter = mAdapter


            mTvTitle.text = mVM.mData?.goodsName
            mTvType.text =  mVM.mData?.category
            mTvYearName.text =  mVM.mData?.years
//            mTvDistrict.text = it?.addressname
//            mTvBoWuGuang.text = it?.owner
            mTvPrice.text = mVM.mPriceStr
            mTvDetail.text =  mVM.mData?.introduce
            mAdapter?.notifyDataSetChanged()

            LoadingDialogUtil.closeDialog()


        mIvCover.setImageBitmap(mVM.getQrBitmap())

        addClickListener(mTvBack)
    }

    override fun onMyViewClick(view: View) {

        if (view.id == R.id.mTvBack){
            finish()
        }
    }

    override fun getData() {

    }
}